import java.util.Scanner;

public class CompanySystem {


// 员工管理系统


    // 属性

    // 存储100个员工信息
    Employee[] coms = new Employee[100];

    Scanner sc = new Scanner(System.in);

    // 主流程
    public void run() {
        System.out.println("欢迎使用xxx员工管理系统");

        while (true) {
            // 打印菜单
            System.out.println("1. 添加员工");
            System.out.println("2. 列出员工");
            System.out.println("3. 删除员工");
            System.out.println("4. 修改员工");
            System.out.println("5. 让所有员工执行work ");
            System.out.println("6. 列出员工总收入列表");
            System.out.println("7. 开车");
            System.out.println("9. 退出系统");

            // 让用户选择
            System.out.println("请输入要执行的操作:");
            int sel = sc.nextInt();

            if (sel == 9) break;

            switch (sel) {
                case 1:
                    add();
                    break;
                case 2:
                    list();
                    break;
                case 3:
                    del();
                    break;
                case 4:
                    modify();
                    break;

                case 5:
                    excuteWork();
                    break;
                case 6:
                    list2();
                    break;
                    case 7:
                    drive();
                    break;
            }
        }

        System.out.println("程序关闭中，欢迎在再次使用");


    }


    public void add() {
        System.out.println("添加员工功能");

        System.out.println("1.添加司机");
        System.out.println("2.添加销售人员");
        System.out.println("3.添加主管");
        int p = sc.nextInt();

        Driver driver;
        SaleEmployee saleEmployee;
        SaleWing saleWing;

        System.out.println("请输入员工编号，姓名，工资");

        // 1. 输入员工信息
        int id = sc.nextInt();
        String name = sc.next();
        double wage = sc.nextDouble();

        // 2. 放入员工对象


        // 3. 把员工对象放入数组
        for (int i = 0; i < 100; i++) {
            if (coms[i] == null) {
                if (p == 1)
                    coms[i] = new Driver(id, name, wage);
                else if (p == 2) {

                    coms[i] = new SaleEmployee(id, name, wage);
                } else if (p == 3) {

                    coms[i] = new SaleWing(id, name, wage);
                }
                break;
            }
        }

    }


    public void del() {
        System.out.println("删除员工功能");


        System.out.println("请输入删除员工的工号：");
        int id = sc.nextInt();

        boolean finded = false;
        for (int i = 0; i < 100; i++) {

            if (coms[i] != null) {
                if (coms[i].getId() == id) {
                    coms[i] = null;
                    System.out.println("删除成功！");
                    finded = true;
                    break;
                }
            }
        }


        if (!finded) {
            System.out.println("未找到该员工");
        }


    }

    public void list() {
        System.out.println("列出员工功能");
        for (int i = 0; i < 100; i++) {
            if (coms[i] != null) {
                System.out.println(coms[i]);
            }
        }
    }

    private void modify() {

        System.out.println("修改员工功能");

        System.out.println("请输入要修改的员工编号：");
        int id = sc.nextInt();
        int index = -1;
        for (int i = 0; i < 100; i++) {

            if (coms[i] != null) {
                if (coms[i].getId() == id) {

                    index = i;
                    break;
                }
            }
        }


        if (index != -1) {
            System.out.println("请输入员工的新姓名、工资");
            String name = sc.next();
            double wage = sc.nextDouble();

            coms[index].setName(name);
            coms[index].setWage(wage);
            System.out.println("修改成功");
        } else {
            System.out.println("未找到要修改的信息");
        }
    }

    private void excuteWork() {

        for (int i = 0; i < 100; i++) {
            if (coms[i] != null) {

                coms[i].wage = coms[i].work();
            }
        }
    }

    private  void list2()
    {
        System.out.println("列出员工功能");
        for (int i = 0; i < 100; i++) {
            if (coms[i] != null) {
                System.out.println(coms[i]);
            }
        }
    }

    private void drive()
    { System.out.println("开车功能");
        for (int i = 0; i < 100; i++) {
            if (coms[i] != null) {
                if(coms[i] instanceof SaleWing||coms[i] instanceof Driver)
                    ((Drive) coms[i]).drive2();
            }
        }

    }
}




